/**
  * Author: Jordi Vilaplana Mayoral <jvilaplana@semicinternet.com>
  * Date: 16/05/2011
  * 
  * OpenFileRename
  * Copyright (C) 2011 Semic Internet
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * 
  * @(#)
  * Description: Renames files following the specified format in Alfresco.
  */

package view;

import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Properties;
import java.util.ResourceBundle;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import model.OpenFileModel;

public class AboutView extends JDialog {

	private static final long serialVersionUID = -2986741046351954091L;
	private Container content;
	private JComboBox cSelectLanguage;
	private JLabel lAbout;
	private JButton bWeb;
	private JButton bLicense;
	private URI uri;
	private URI uLicense;
	private ResourceBundle rLabels;
	private Properties configFile;
	private OpenFileModel model;
	private URL imageURL;
	private GridBagConstraints c;
	private GridBagLayout grid;
	private ImageIcon image;
	private JLabel lPic;
	
	public AboutView(OpenFileModel model) {
		this.model = model;
		rLabels = model.getLabels();
		configFile = model.loadConfiguration();
		content = this.getContentPane();
		content.setPreferredSize(new Dimension(450, 200));
		this.setTitle("About OpenLogView...");
		
		initView();
		
        c.gridx = 0;
        c.gridy = 0;
        content.add(lPic, c);
        c.gridx = 1;
        content.add(lAbout,c);
        
        c.gridy = 1;
        c.gridx = 0;
        content.add(bWeb, c);		
		
		c.gridy = 2;
		c.gridwidth = 2;
		content.add(bLicense, c);
		
		this.pack();
	}
	
	public JComboBox getSelectLanguage() {
		return cSelectLanguage;
	}
	
	public JButton getWeb() {
		return bWeb;
	}
	
	public JButton getLicense() {
		return bLicense;
	}
	
	public URI getUri() {
		return uri;
	}
	
	public URI getULicense() {
		return uLicense;
	}
	
	public void initView() {
		try {
			uLicense = new URI("http://creativecommons.org/licenses/GPL/3.0/");
			uri = new URI("http://www.semicinternet.com");
		} catch (URISyntaxException e) { e.printStackTrace(); }
		grid = new GridBagLayout();
		content = this.getContentPane();
		c = new GridBagConstraints();
		lAbout = new JLabel();
		image = new ImageIcon();
		bWeb = new JButton();
		bLicense = new JButton();
		
		imageURL = main.OpenFileRename.class.getResource("olv.png");
		
		image.setImage(Toolkit.getDefaultToolkit().getImage(imageURL));
		lPic = new JLabel(image);
		
		content.setLayout(grid);
		
		c.ipadx = 2; c.ipady = 2; c.weightx = 1; c.weighty = 1;
		
		bWeb.setText(rLabels.getString("projectWebstie"));
		bWeb.setHorizontalAlignment(SwingConstants.LEFT);
		bWeb.setBorderPainted(false);
		bWeb.setOpaque(false);
		bWeb.setBackground(Color.WHITE);
		bWeb.setToolTipText(uri.toString());
		bWeb.setForeground(Color.BLUE);
		
		bLicense.setText(rLabels.getString("projectLicense"));
		bLicense.setHorizontalAlignment(SwingConstants.LEFT);
		bLicense.setBorderPainted(false);
		bLicense.setOpaque(false);
		bLicense.setBackground(Color.WHITE);
		bLicense.setToolTipText(uLicense.toString());
		bLicense.setIcon(new ImageIcon(main.OpenFileRename.class.getResource("cc-GPL-a.png")));
		bLicense.setForeground(Color.BLUE);
		
		lAbout.setText("<html><p><font color=\"red\" size=\"6\"><b>" + 
				configFile.getProperty("applicationName") +
				"</b></font></p><p><font color=\"#848484\">" + rLabels.getString("version") + " " + 
				configFile.getProperty("applicationVersion") + "</font></p><br /><p>" +	"<font color=\"blue\">" + 
				rLabels.getString("createdBy") + " <i>Jordi Vilaplana</i>.</font></p><p>2011</p></html>");
	}

}
